
local MenuScene = class("MenuScene", function()
    return display.newScene("MenuScene")
end)



function MenuScene:ctor()

    local bgNode = display.newNode()
    self:addChild(bgNode)

    local bg = display.newScale9Sprite("ui/maintab_topbar.png", display.cx, display.cy, CCSizeMake(display.width, display.height))
    bgNode:addChild(bg, 0)

    local uiNode = display.newNode()
    bgNode:addChild(uiNode, 1)


	local headerSprite = display.newSprite("ui/widget_head.9.png")
    local header = display.newScale9Sprite("ui/widget_head.9.png", display.cx, display.height - headerSprite:getContentSize().height,
    CCSizeMake(display.width, headerSprite:getContentSize().height * 2))
    uiNode:addChild(header)
	
	local mainTabBg = display.newSprite("ui/man_tab_select_bg.png")
	mainTabBg:retain()
	local bottom = display.newScale9Sprite("ui/widget_head.9.png", 0, 0,
    CCSizeMake(display.width, mainTabBg:getContentSize().height * 1.5 + 4))
	bottom:setPosition(display.cx, bottom:getContentSize().height / 2)
    bottom:setRotation(180)
    uiNode:addChild(bottom)

    local myBookcase = ui.newTTFLabel({
        text = "我的书架",
        x = 10,
        y = header:getContentSize().height * 0.5,
        size = 28,
        color = ccc3(100, 100, 100)
    })
    header:addChild(myBookcase)

    local myBookCaseFlag = display.newSprite("ui/login_dialog_more_account.png")
    myBookCaseFlag:setPosition(myBookcase:getContentSize().width + 20,
        header:getContentSize().height / 2 - myBookcase:getContentSize().height / 2 + myBookCaseFlag:getContentSize().height)
    header:addChild(myBookCaseFlag)

	local bookCaseSpriteBg = display.newScale9Sprite("ui/man_tab_select_bg.png", 0, 0, CCSizeMake(display.width / 2, bottom:getContentSize().height - 4))
	bookCaseSpriteBg:setPosition(display.width / 4, bookCaseSpriteBg:getContentSize().height / 2)
    uiNode:addChild(bookCaseSpriteBg)

	local bookCaseBtn = nil
	local bookStoreBtn = nil
	
	local bookCaseLabel = nil
	local bookStoreLabel = nil
	
	bookCaseBtn = ui.newImageMenuItem({
		image = "ui/maintab_bookstand_icon_hover.png",
		x = display.width / 4,
		y = bookCaseSpriteBg:getContentSize().height / 1.6,
		listener = function()
			local sprite = display.newSprite("ui/maintab_bookstand_icon_hover.png")
			tolua.cast(bookCaseBtn:getNormalImage(), "CCSprite")
			:setDisplayFrame(CCSpriteFrame:create("ui/maintab_bookstand_icon_hover.png", 
			CCRectMake(0, 0, sprite:getContentSize().width, sprite:getContentSize().height)))

            bookCaseLabel:setColor(ccc3(255, 255, 255))
            bookStoreLabel:setColor(ccc3(100, 100, 100))
			
			bookCaseSpriteBg:runAction(transition.sequence({
				CCMoveTo:create(0.2, CCPointMake(display.width / 4, bookCaseSpriteBg:getContentSize().height / 2)),
				CCCallFunc:create(function()
					local sprite2 = display.newSprite("ui/maintab_city_icon.png")
					tolua.cast(bookStoreBtn:getNormalImage(), "CCSprite")
					:setDisplayFrame(CCSpriteFrame:create("ui/maintab_city_icon.png", 
					CCRectMake(0, 0, sprite2:getContentSize().width, sprite2:getContentSize().height)))
				end)
			}))
		end
	})
	
	
	bookStoreBtn = ui.newImageMenuItem({
		image = "ui/maintab_city_icon.png",
		x = display.width * (3 / 4),
		y = bookCaseSpriteBg:getContentSize().height / 1.6,
		listener = function()

            bookCaseLabel:setColor(ccc3(100, 100, 100))
            bookStoreLabel:setColor(ccc3(255, 255, 255))
		
			local sprite2 = display.newSprite("ui/maintab_city_icon_hover.png")
			tolua.cast(bookStoreBtn:getNormalImage(), "CCSprite")
			:setDisplayFrame(CCSpriteFrame:create("ui/maintab_city_icon_hover.png", 
			CCRectMake(0, 0, sprite2:getContentSize().width, sprite2:getContentSize().height)))
			
			bookCaseSpriteBg:runAction(transition.sequence({
				CCMoveTo:create(0.2, CCPointMake(display.width * (3 / 4), bookCaseSpriteBg:getContentSize().height / 2)),
				CCCallFunc:create(function()
					local sprite = display.newSprite("ui/maintab_bookstand_icon.png")

					tolua.cast(bookCaseBtn:getNormalImage(), "CCSprite")
					:setDisplayFrame(CCSpriteFrame:create("ui/maintab_bookstand_icon.png", 
					CCRectMake(0, 0, sprite:getContentSize().width, sprite:getContentSize().height)))

				end)
			}))
		end
	})
	
	local menu = ui.newMenu({bookCaseBtn, bookStoreBtn})
    uiNode:addChild(menu)
	
	bookCaseLabel = ui.newTTFLabel({
		text = "书架",
		size = 20,
		color = ccc3(255, 255, 255),
		align = ui.TEXT_ALIGN_CENTER,
	})
	bookCaseLabel:setPosition(display.width / 4, bookCaseSpriteBg:getContentSize().height / 4)
    uiNode:addChild(bookCaseLabel)
	
	bookStoreLabel = ui.newTTFLabel({
		text = "书城",
		size = 20,
		color = ccc3(100, 100, 100),
		align = ui.TEXT_ALIGN_CENTER,
	})
	bookStoreLabel:setPosition(display.width * (3 / 4), bookCaseSpriteBg:getContentSize().height / 4)
    uiNode:addChild(bookStoreLabel)

    local bookCasesNode = display.newNode()
    bgNode:addChild(bookCasesNode, 0)

    local bookCaseSprite = display.newSprite("ui/book_case.png")
    for i = 1, 6 do
        local bookCase = display.newScale9Sprite("ui/book_case.png", 0, 0, CCSizeMake(display.width, bookCaseSprite:getContentSize().height))
        if i == 1 then
            bookCase:setPosition(display.cx, display.height - 300)
        else
            bookCase:setPosition(display.cx, display.height - 300 - (i - 2) * 200)
        end
        bookCasesNode:addChild(bookCase, 2)
    end




end

return MenuScene
